1. Technical Field
The present invention relates to data processing systems and, in particular, to the shutdown process of a Java based server. Still more particularly, the present invention provides a method, apparatus, and program for keeping a Java Virtual Machine running during the shutdown process of a Java based server executing daemon threads.
2. Description of Related Art
Java is a programming language designed to generate applications that can run on all hardware platforms without modification. Java was modeled after C++, and Java programs can be called from within hypertext markup language (HTML) documents or launched stand alone. The source code of a Java program is compiled into an intermediate language called “bytecode,” which cannot run by itself. The bytecode must be converted (interpreted) into machine code at runtime. When running a Java application, a Java interpreter (Java Virtual Machine) is invoked. The Java Virtual Machine (JVM) translates the bytecode into machine code and runs it. As a result, Java programs are not dependent on any specific hardware and will run in any computer with the Java Virtual Machine software.
Remote Method Invocation (RMI) is a remote procedure call (RPC), which allows Java objects (software components) stored in a network to be run remotely. In the Java distributed object model, a remote object is one whose methods can be invoked from another JVM, potentially on a different host.
The Java Virtual Machine specification requires that the JVM exit when all non-daemon threads have finished execution. The JVM will exit when this condition is met regardless of the state of any daemon threads still running in the JVM. Thus, any data stored by or operations in progress by any daemon threads in the JVM may potentially be lost. Also, any persistent files that those threads are working with may potentially be corrupted or only partially updated, resulting in data files in an unknown state.
In a Java application in which the developer has control of the thread creation process, the developer may simply set important threads as normal (non-daemon) threads to ensure that these problems do not occur. However, in a Java application that uses RMI, the thread creation process is performed in the Java RMI code and cannot be altered. The Java RMI code automatically creates threads as daemon threads. Java threads can only be set as normal or daemon before they begin execution. Therefore, the use of RMI code may result in unavoidable problems when the JVM exits.
Therefore, it would be advantageous to provide a mechanism for keeping the JVM running during shutdown until the daemon threads complete execution.